/*
	contains the main kernel initialisation functionality

	Author: Aidan Goddard 25/6/14
*/

#include "printf.h"
#include "memory.h"
#include "kernel_fixed_table.h"

uint32_t kinit()
{
	// set initial state
	KERNEL->system_state = SYSTEM_STATE_BOOT;
	KERNEL->CPU_count = 4;

	// print hello message
	printf("Beginning kernel initialisation");

	// setup memory system
	uint32_t error = 0;
	uint64_t memory_amount = memory_init(&error);
	if(!memory_amount)
	{
		printf("ERROR: could not initialise memory system: 0x%x", error);
		return -1;
	}

	// get CPU topology information
	// (ACPI tables and CPUID)

	printf("FLARGLEBARGLE %u", sizeof(size_t));


	// finish initialsing memory (SMP stuff)
	uint64_t error2 = memory_init_step2(&error);
	if(!error2)
	{
		printf("ERROR: could not initialise memory system SMP controls: 0x%x", error);
		return -3;
	}


	return -1;
}